package com.sdy.web;

import com.alibaba.fastjson.JSONObject;
import com.sdy.po.Company;
import com.sdy.po.Order;
import com.sdy.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    /**
     * 加载交易记录模块
     * @param model
     * @param session
     * @return
     */
    @RequestMapping("")
    public String order(Model model,HttpSession session){

        Company company = (Company) session.getAttribute("contactCompany");
        System.out.println(company);
        List<Order> orderList = orderService.getListByCompanyId(company.getId());

        if (orderList.size()>0){
            model.addAttribute("hasOrder",true);
            model.addAttribute("orderList",orderList);
            return "pages/transection";
        }

        model.addAttribute("hasOrder",false);

        return "pages/transection";
    }

    @RequestMapping("/getAll")
    public String getAllOrder(Model model){
        model.addAttribute("orderList",orderService.getAll());
        return "allOrder";
    }

    /**
     * 根据公司信息查询
     * @param session
     * @return
     */
    @ResponseBody
    @RequestMapping("/getOrderList")
    public JSONObject getOrderList(HttpSession session){
        JSONObject jsonObject = new JSONObject();
        Company company = (Company) session.getAttribute("contactCompany");
        System.out.println(company);
        jsonObject.put("data",orderService.getListByCompanyId(company.getId()));
        return jsonObject;
    }

    @RequestMapping("/Insert")
    public JSONObject InsertOrderByUser(){

        return null;
    }



}
